package fr.mystnihon.game.model.actor;

import fr.mystnihon.game.engine.DamageCalculator;
import fr.mystnihon.game.model.ability.Competence;
import fr.mystnihon.game.model.item.Item;
import fr.mystnihon.game.model.item.Weapon;

public class Personnage {

	public long _id;
	public int mHealth;
	public int mMana;
	public String mName;

	private int mLevel = 1;
	private int mStrength = 10;
	private int mDefense = 10;
	private int mMagick = 10;
	private int mSpirit = 10;
	private int mEsquive = 10;

	private boolean mIsAlive = true;

	private Weapon mWeapon;
	private Personnage mTarget;

	public Personnage() {

	}

	public Personnage(String name) {
		this(name, 0, 0);
	}

	public Personnage(String name, int health, int mana) {
		this(name, health, mana, null);
	}

	public Personnage(String name, int health, int mana, Weapon weapon) {

		mWeapon = weapon;
		mName = name;
		mHealth = health;
		mMana = mana;
	}

	public void attack(Personnage p) {
		setTarget(p);
		mTarget.getDamage(DamageCalculator.calculatePhysicalDamage(mTarget,
				this));
		System.out.println(getName() + " attaque " + p.getName()
				+ " et lui inflige " + ((Characters) p).lastDamageDone
				+ " de degats.");
		System.out.println(getName() + " vie restante : " + getHealth() + "PV");
		System.out.println(p.getName() + " vie restante : " + p.getHealth()
				+ "PV");
		if (!p.isAlive()) {
			System.out.println(p.getName() + " est mort.");
		}
	}

	public void useCompetence(Competence competence) {

	}

	public void getDamage(double d) {
		setHealth((int) (mHealth - d));
	}

	public void useObject(Item object) {
		object.setTarget(this);
	}

	public int getHealth() {
		return mHealth;
	}

	public void setHealth(int health) {
		if (health > 0) {
			mHealth = health;
		} else {
			mHealth = 0;
			mIsAlive = false;
		}
	}

	public int getMana() {
		return mMana;
	}

	public void setMana(int mana) {
		if (mana >= 0) {
			mMana = mana;
		} else {
			mMana = 0;
		}
	}

	public String getName() {
		return mName;
	}

	public void setName(String name) {
		mName = name;
	}

	public int getStrenght() {
		return mStrength;
	}

	public void setStrenght(int strenght) {
		mStrength = strenght;
	}

	public int getDefense() {
		return mDefense;
	}

	public void setDefense(int defense) {
		mDefense = defense;
	}

	public int getMagie() {
		return mMagick;
	}

	public void setMagie(int magie) {
		mMagick = magie;
	}

	public int getSpirit() {
		return mSpirit;
	}

	public void setSpirit(int spirit) {
		mSpirit = spirit;
	}

	public int getEsquive() {
		return mEsquive;
	}

	public void setEsquive(int esquive) {
		mEsquive = esquive;
	}

	public boolean isAlive() {
		return mIsAlive;
	}

	public void setAlive(boolean isAlive) {
		mIsAlive = isAlive;
	}

	public void setLevel(int level) {
		mLevel = level;
	}

	public int getLevel() {
		return mLevel;
	}

	public void setWeapon(Weapon weapon) {
		mWeapon = weapon;
	}

	public Weapon getWeapon() {
		return mWeapon;
	}

	public void setTarget(Personnage target) {
		mTarget = target;
	}

	public Personnage getTarget() {
		return mTarget;
	}
}
